package com.eportal.core;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Hashtable;
import java.util.List;
import java.util.Random;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import net.sf.cindy.Session;
import net.sf.cindy.SessionAdapter;
import net.sf.cindy.impl.AutoCloseEventGenerator;
import net.sf.cindy.impl.ByteArrayMessage;
import net.sf.cindy.impl.SocketSession;

import com.eportal.ORM.WtPepJnls;
import com.eportal.gd.Conf;

public class Util {
	public static String zd_ip = "172.16.1.21";
	public static int zd_port = 3008;
	public static String ROOTPATH = "";
	public static String VER = "v1.3.5";
	public static SocketSession session = new SocketSession();
	public static SocketSession zd_session = new SocketSession();
	public static Connection c;

	public static String checkBank(String bank) {
		String str = "";
		// "0100", "邮储银行"
		// "0102", "中国工商银行"
		// "0103", "中国农业银行"
		// "0105", "中国建设银行"
		// "0302", "中信银行"
		// "0303", "中国光大银行"
		// "0305", "中国民生银行"
		// "0306", "广东发展银行"
		// "0308", "招商银行"
		// "0309", "兴业银行"
		// "0301", "交通银行"
		// "0307", "深圳发展银行"
		// "0410", "中国平安银行"
		if (bank.equals("工商银行"))
			str = "0102";
		if (bank.equals("光大银行"))
			str = "0303";
		if (bank.equals("广发银行"))
			str = "0306";
		if (bank.equals("建设银行"))
			str = "0105";
		if (bank.equals("交通银行"))
			str = "0301";
		if (bank.equals("民生银行"))
			str = "0305";
		if (bank.equals("农业银行"))
			str = "0103";
		if (bank.equals("平安银行"))
			str = "0410";
		if (bank.equals("深圳发展银行"))
			str = "0307";
		if (bank.equals("兴业银行"))
			str = "0309";
		if (bank.equals("邮储银行"))
			str = "0100";
		if (bank.equals("招商银行"))
			str = "0308";
		if (bank.equals("中信银行"))
			str = "0302";
		return str;
	}

	public static void download(URL url, String filepath) throws Exception {
		HttpURLConnection connection = (HttpURLConnection) url.openConnection();
		InputStream is = connection.getInputStream();
		StringBuffer buffer = new StringBuffer();
		InputStreamReader read = new InputStreamReader(is);
		BufferedReader reader = new BufferedReader(read);
		String str = new String();
		while ((str = reader.readLine()) != null) {
			buffer.append(str + "\r\n");
			// 更新数据
			System.out.println("CP对账");
			String sql = "";
			String data[] = str.split("\\|");
			if (data.length > 10) {
				String msg = "";
				String orderid = data[2];
				String trancde = data[3];
				String cpdate = data[9];
				String cptrace = data[10];
				String ans = data[5];
				System.out.println(ans);
				if (ans.equals("1001"))
					ans = "00";
				else
					ans = ans.substring(2);
				String pepdate = data[6];
				msg = (String) Util.CHINALIST.get(ans);
				if (msg == null || msg.equals(""))
					msg = "交易失败";
				sql = "update net_pay_jnls set SETTLEDATE = '" + cpdate
						+ "',CUPSTRACENUM = '" + cptrace + "',RESPCODE = '"
						+ ans + "',RESPDESC = '" + msg
						+ "' where MERORDERNUM = '" + orderid
						+ "' and PEPDATE = '" + pepdate + "'";
				try {
					int q = oracle(sql);
					System.out.println("update:" + q);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
		String fileName = url.getFile();
		fileName = fileName.substring(fileName.lastIndexOf('/') + 1);
		File file = new File(filepath + "/" + fileName);
		FileOutputStream os = new FileOutputStream(file);
		os.write(buffer.toString().getBytes());
		is.close();
		os.close();
	}

	public static String getBatchID() {
		String str = "";
		str += Conf.userID;
		str += Util.getCurrentDate("yyyyMMdd");
		Random random = new Random();
		int id = random.nextInt(99999999);
		str += Util.left_(id + "", "0", 8);
		return str;
	}

	public static int oracle(String sql) throws SQLException {
		int i = 0;
		if (c == null || c.isClosed()) {
			c = myOracle.getDataSource("172.16.1.2", "1521", "pay20", "pay20",
					"pep").getConnection();
		}
		PreparedStatement ps = c.prepareStatement(sql);
		System.out.println(sql);
		i = ps.executeUpdate();
		ps.close();
		return i;
	}

	public static String sendToGD(String url, String msg) throws Exception {
		String u = "http://" + Conf.gd_ip + ":" + Conf.gd_port;
		System.out.println(u);
		String tmp = "";
		HttpURLConnection httpConn = null;
		InputStream in = null;
		InputStreamReader read = null;
		URL urls = new URL(u);
		httpConn = (HttpURLConnection) urls.openConnection();
		httpConn.setRequestMethod("POST");
		httpConn.setDoOutput(true);
		httpConn.setRequestProperty("POST", url);
		OutputStreamWriter out = new OutputStreamWriter(httpConn
				.getOutputStream(), "GBK");
		out.write(msg);
		out.flush();
		in = httpConn.getInputStream();
		read = new InputStreamReader(in, "GBK");
		BufferedReader reader = new BufferedReader(read);
		String str = new String();
		while ((str = reader.readLine()) != null) {
			tmp += str + "\r\n";
		}
		System.out.println(tmp);
		out.close();
		in.close();
		return tmp;
	}

	// yyyy-MM-dd HH:mm:ss
	public static String getDateTime(String format) {
		String str = "";
		// Calendar cal = Calendar.getInstance();
		SimpleDateFormat formatter = new SimpleDateFormat(format);
		str = formatter.format(new Date().getTime());
		return str;
	}

	public static String killLeftZero(String src) {
		if (src.startsWith("0")) {
			int p = 0;
			for (int i = 0; i < src.length(); i++) {
				if (src.charAt(i) != '0') {
					p = i;
					break;
				}
			}
			return src.substring(p);
		} else
			return src;
	}

	public static String clearString(String msg) {
		if (msg == null)
			return null;
		int p = 0;
		char[] c = msg.toCharArray();
		for (int i = 0; i < c.length; i++) {
			if ((int) c[i] == 0) {
				p = i;
				break;
			}
		}
		return new String(c, 0, p);
	}

	public static String clearByte(byte[] b) {
		String tmp = "";
		int p = 0;
		for (int i = 0; i < b.length; i++) {
			if (b[i] == 0) {
				p = i;
				break;
			}
		}
		tmp = new String(b, 0, p);
		return tmp;
	}

	public static String left_(String src, String split, int length) {
		String tmp = "";
		try {
			for (int i = 0; i < length - src.getBytes("gb2312").length; i++) {
				tmp += split;
			}
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return tmp + src;
	}

	public static String right_(String src, String split, int length) {
		String tmp = "";
		try {
			for (int i = 0; i < length - src.getBytes("gb2312").length; i++) {
				tmp += split;
			}
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return src + tmp;
	}

	// type=1 有回包 0 无

	public static byte[] appendByte(byte[] src, byte[] n) {
		if (src == null)
			return n;
		byte[] tmp = new byte[src.length + n.length];
		System.arraycopy(src, 0, tmp, 0, src.length);
		System.arraycopy(n, 0, tmp, src.length, n.length);
		return tmp;
	}

	public static String getCurrentDate(String format) {
		SimpleDateFormat f = new SimpleDateFormat(format);
		Date d = new Date();

		return f.format(d);
	}

	public static byte[] subByte(byte[] src, int start, int end) {
		byte[] tmp = new byte[end - start];
		int k = 0;
		for (int i = start; i < end; i++) {
			tmp[k] = src[i];
			k++;
		}
		return tmp;
	}

	public static String addZero(String old, int num) {
		String str = "";
		if (old == null || old.equals("")) {
			old = "";
		}
		if (old.length() > num) {
			return old;
		}
		for (int i = 0; i < num - old.length(); i++) {
			str += "0";
		}
		str = str + old;
		return str;
	}

	public static String moveRightTwo(String str) {

		// str = Float.valueOf(str)+"";

		if (str == null) {
			str = "0";
		}
		if (str.equals("")) {
			return "0";
		}
		if (str.indexOf(".") != -1) {
			if (str.endsWith("\\.")) {
				return str.substring(0, str.length() - 1) + "00";
			}
			String tmp[] = str.split("\\.");
			if (tmp[1].length() == 1) {
				return tmp[0] + tmp[1] + "0";
			}
			if (tmp[1].length() == 2) {
				return tmp[0] + tmp[1];
			}
			if (tmp[1].length() > 2) {
				return tmp[0] + tmp[1].substring(0, 2);
			}

		} else {
			return str + "00";
		}
		return "";
	}

	public static String moveLeftTwo(String str) {

		// str = Float.valueOf(str)+"";
		if (str == null) {
			str = "0";
		}
		if (str.equals("")) {
			return "0";
		}
		if (str.indexOf(".") == -1) {
			str = str + ".";
		}
		if (str.indexOf(".") == 1)
			return "0.0" + str.replace(".", "");
		char tmp[] = str.toCharArray();
		String s = "";
		for (int i = 0; i < tmp.length; i++) {
			if (str.indexOf(".") - 2 == i) {
				s += ".";
			}
			if (tmp[i] != '.')
				s += tmp[i];
		}
		return s;
	}

	public static String getAMT(String old) {

		if (old == null) {
			old = "";
		}
		String tmp = "";
		for (int i = old.length(); i < 12; i++) {
			tmp += "0";
		}
		old = tmp + old;
		return old;
	}

	public static String getFEE(String old) {

		if (old == null) {
			old = "";
		}
		String tmp = "";
		for (int i = old.length(); i < 8; i++) {
			tmp += "0";
		}
		old = tmp + old;
		return old;
	}

	public static String FormatSum(String sum) {
		if (sum == null||sum.equals("null")) {
			return "";
		}
		if (sum.equals("") || sum.equals("0") || sum.equals("-")) {
			return "0";
		}
		String m = "";
		if (sum.startsWith("-")) {
			m = "-";
			sum = sum.replace("-", "");
		}
		// System.out.println("sum" + sum);
		sum = "00" + sum.trim();
		// System.out.println("sum" + sum);
		String sum2 = "." + sum.substring(sum.length() - 2, sum.length());
		String sum1 = KillZero(sum.substring(0, sum.length() - 2));
		sum1 += sum2;
		if (sum1.startsWith(".")) {
			sum1 = "0" + sum1;
		}
		return m + sum1;
	}

	public static String KillZero(String sum) {
		String temp = "";
		for (int i = 0; i < sum.length(); i++) {
			if (sum.charAt(i) != '0' || i == sum.length() - 1) {
				temp = sum.substring(i, sum.length());
				break;
			}
		}
		return temp;
	}

	public static void saveToFile(String path, String msg) throws Exception {
		File file = new File(path);
		FileOutputStream fos = new FileOutputStream(file);
		fos.write(msg.getBytes("UTF-8"));
		fos.flush();
		fos.close();
	}

	public static String readByFile(String path) throws Exception {
		String msg = "";
		File file = new File(path);
		FileInputStream fis = new FileInputStream(file);
		byte[] tmp = new byte[fis.available()];
		fis.read(tmp);
		msg = new String(tmp);
		return msg;
	}

	public static String toInCard(String src) {
		String tmp = src == null ? "" : src.trim();
		tmp = formatString(tmp);
		if (tmp.indexOf("Y1") != -1) {
			tmp = tmp.substring(0, tmp.indexOf("Y1"));
		}

		if (tmp.length() < 11)
			return tmp;
		else {
			tmp = tmp.substring(0, 6) + "-****-****-"
					+ tmp.substring(tmp.length() - 4);
		}
		return tmp;
	}

	public static final String[][] chianpaycode = { { "00", "承兑或交易成功" },
			{ "23", "不可接受的交易费" }, { "25", "找不到原始交易" }, { "30", "格式错误" },
			{ "31", "交换中心不支持的银行" }, { "33", "过期的卡" }, { "34", "有作弊嫌疑" },
			{ "35", "受卡方与代理方联系" }, { "36", "受限制的卡" }, { "00", "承兑或交易成功" },
			{ "37", "受卡方电话通知代理方安全部门" }, { "38", "超过允许的PIN试输入" },
			{ "39", "无贷记账户" }, { "40", "请求的功能尚不支持" }, { "41", "挂失卡" },
			{ "42", "无此账户" }, { "43", "被窃卡" }, { "44", "无此投资账户" },
			{ "51", "资金不足" }, { "52", "无此支票账户" }, { "53", "无此储蓄卡账户" },
			{ "54", "过期的卡" }, { "55", "密码不正确" }, { "56", "无此卡记录" },
			{ "57", "不允许持卡人进行的交易仅针对持卡人不支持的情况" }, { "58", "不允许终端进行的交易" },
			{ "59", "有作弊嫌疑" }, { "60", "受卡方与代理方联系" }, { "61", "超出金额限制" },
			{ "62", "受限制的卡" }, { "63", "侵犯安全" }, { "64", "原始金额错误" },
			{ "65", "超出取款次数限制" }, { "66", "受卡方通知受理方安全部门" },
			{ "67", "强行受理（要求在自动会员机上没收此卡）" },
			{ "68", "接收的响应超时联网机构收到迟到的承兑或拒绝应答" }, { "75", "允许的输入密码次数超限" },
			{ "76", "无效账户" }, { "91", "发卡方不能操作" } };

	public static final String[][] define = { { "00", "成功" }, { "10", "保留" },
			{ "11", "银行判消息鉴别失败" }, { "12", "银行判报头格式检查出错" },
			{ "13", "银行判记录格式检查出错" }, { "14", "中心判消息鉴别失败没转发" },
			{ "15", "中心判报头格式出错没转发" }, { "16", "中心判记录格式出错没转发" },
			{ "17", "中心判应答消息鉴别失败" }, { "18", "中心已关闭" }, { "19", "日期不符" },
			{ "21", "数据尚未生成" }, { "22", "无此请求数据" }, { "23", "请求功能不支持" },
			{ "24", "重复提交的数据" }, { "25", "无效入网单位代码" }, { "26", "无效交易" },
			{ "27", "无效金额" }, { "28", "无此银行" }, { "31", "入网单位没签到" },
			{ "32", "银行无应答或返回" }, { "33", "银行故障，无法转发" }, { "34", "银行关闭" },
			{ "41", "签到、签退失败" }, { "42", "对账不平" }, { "43", "对账出错" },
			{ "44", "与原始记录不匹配" }, { "45", "授权（新增或撤销）不成功" }, { "50", "收费子类错误" },
			{ "51", "无效付款人帐号" }, { "52", "付款人帐号非本行" }, { "53", "帐号与户名不符" },
			{ "54", "帐户余额不足" }, { "55", "存折或卡已挂失" }, { "56", "帐户已冻结" },
			{ "57", "未登折数超出" }, { "58", "已列入黑名单" }, { "59", "付款人帐号已销户" },
			{ "60", "授权号相符，其它要素不符" }, { "61", "授权号无效或不符" },
			{ "62", "未办理委托或授权" }, { "63", "授权号还没生效" }, { "64", "无效凭证号" },
			{ "65", "协议特殊条款拒绝" }, { "66", "计量对象号码不符" }, { "67", "无效金额" },
			{ "68", "金额超出限制" }, { "69", "其它原因拒绝" }, { "70", "记录重复" },
			{ "71", "无原始交易记录" }, { "72", "交易违法、不能完成" },
			{ "73", "交换中心或接收方不能操作" }, { "74", "中间网络设施找不到或无法到达" },
			{ "75", "交换中心收不到接收方应答" }, { "76", "系统异常、失效" }, { "77", "文件长度不符" },
			{ "78", "撤销" }, { "80", "收费单位不支持实时认证" },
			{ "81", "客户有欠费，不允许变更委托协议" }, { "82", "无效计量对象号码" },
			{ "83", "计量号与计量对象户名不符" }, { "84", "其它原因不允许变更委托协议" },
			{ "85", "收费单位与授权号不符" }, { "97", "保留" }, { "99", "初始值" },
			{ "49", "协议号与扣款账户不符" }, { "FF", "初始状态" } };

	public static Hashtable CODELIST;
	public static Hashtable CHINALIST;

	static {
		int s = chianpaycode.length;
		CHINALIST = new Hashtable(s + 1);
		for (int i = 0; i < s; i++) {
			CHINALIST.put(chianpaycode[i][0], chianpaycode[i][1]);
		}

		int size = define.length;
		CODELIST = new Hashtable(size + 1);
		for (int i = 0; i < size; i++) {
			CODELIST.put(define[i][0], define[i][1]);
		}
	}

	public static void sendSMS(String msg, String phone) throws Exception {
		URL url = new URL("http://192.168.5.110/sms/sms");
		URLConnection connection = url.openConnection();
		connection.setDoOutput(true);
		OutputStreamWriter out = new OutputStreamWriter(connection
				.getOutputStream(), "UTF-8");
		System.out.println("发送短信" + phone + " " + msg);
		String url1 = "phost=192.168.5.39&papi=wuliu&pusr=djm&ppwd=djm5945&pdb=mas&pmobiles="
				+ phone + "&pmsg=" + msg;
		// System.out.println("smsURL="+url1);
		out.write(url1);
		out.flush();
		out.close();
		DataInputStream read = new DataInputStream(connection.getInputStream());
		byte tmp2[] = new byte[1024];
		read.read(tmp2);
		read.close();
	}

	public static void sendSMSToServer(String mobiles, String content,
			String flag) throws Exception {
		if (!session.isConnected()) {
			// 开始连接
			session.setSocketAddress(new InetSocketAddress("192.168.5.110",
					8999));
			// 设置事件产生器
			session.setEventGenerator(new AutoCloseEventGenerator());
			session.start(true);
		}
		String xmlstr = "<sms><mobiles>"
				+ mobiles
				+ "</mobiles><content>"
				+ content.replace("\r\n", " ").replace("\n", " ")
				+ "</content><src_id>001</src_id><send_time></send_time><is_wap>"
				+ flag + "</is_wap><url></url></sms>";
		System.out.println(xmlstr);
		session.blockWrite(new ByteArrayMessage(xmlstr.getBytes("GBK")));
		session.close();
	}

	public static void sendBillToServer(Bill bill) throws Exception {
		if (!zd_session.isConnected()) {
			zd_session.setSocketAddress(new InetSocketAddress(zd_ip, zd_port));
			zd_session.setEventGenerator(new AutoCloseEventGenerator());
			zd_session.start(true);
		}

		System.out.println("send:" + bill.toString());
		zd_session.blockWrite(new ByteArrayMessage(bill.toString().getBytes(
				"GBK")));
		zd_session.addSessionListener(new SessionAdapter() {
			public void messageReceived(Session session,
					net.sf.cindy.Message message) {
				System.out.println("收到信息：" + message);
			}
		});
		zd_session.close();
	}

	public static String addSpace(String src, int length) {
		if (src == null)
			src = "";
		String tmp = "";
		for (int i = 0; i < length - src.length(); i++) {
			tmp += " ";
		}
		return src + tmp;
	}

	public static String numtochinese(String input) {
		String s1 = "零壹贰叁肆伍陆柒捌玖";
		String s4 = "分角整元拾佰仟万拾佰仟亿拾佰仟";
		String temp = "";
		String result = "";
		if (input == null)
			return "输入字串不是数字串只能包括以下字符（′0′～′9′，′.′)，输入字串最大只能精确到仟亿，小数点只能两位！";
		temp = input.trim();
		float f;
		try {
			f = Float.parseFloat(temp);

		} catch (Exception e) {
			return "输入字串不是数字串只能包括以下字符（′0′～′9′，′.′)，输入字串最大只能精确到仟亿，小数点只能两位！";
		}
		int len = 0;
		if (temp.indexOf(".") == -1)
			len = temp.length();
		else
			len = temp.indexOf(".");
		if (len > s4.length() - 3)
			return ("输入字串最大只能精确到仟亿，小数点只能两位！");
		int n1, n2 = 0;
		String num = "";
		String unit = "";

		for (int i = 0; i < temp.length(); i++) {
			if (i > len + 2) {
				break;
			}
			if (i == len) {
				continue;
			}
			n1 = Integer.parseInt(String.valueOf(temp.charAt(i)));
			num = s1.substring(n1, n1 + 1);
			n1 = len - i + 2;
			unit = s4.substring(n1, n1 + 1);
			result = result.concat(num).concat(unit);
		}
		if ((len == temp.length()) || (len == temp.length() - 1))
			result = result.concat("整");
		if (len == temp.length() - 2)
			result = result.concat("零分");
		return result;
	}

	public static int getDayByMouth(String mouth) {
		mouth = mouth + "01";
		int i = 0;
		Date date = new Date();
		DateFormat format = new SimpleDateFormat("yyyyMMdd");
		try {
			date = format.parse(mouth);
			while (true) {
				String strDate = format.format(date);
				i++;

				if (strDate.substring(6).equals("01") && !strDate.equals(mouth)) {
					break;
				}
				Calendar theCa = Calendar.getInstance();
				theCa.setTime(date);
				theCa.add(theCa.DATE, 1);
				date = theCa.getTime();
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return i - 1;
	}

	public static String formatString(String old) {
		if (old == null)
			return "";
		String str = "";
		old = old.trim();
		if (old.startsWith("PA08")) {
			old = old.substring(4);
		}
		if (old.equals("KLTN1000"))
			return "货款";
		if (old.equals("KLTN1001"))
			return "押金";
		if (old.equals("KLTN1002"))
			return "F99服务费";
		if (old.equals("KLTN1003"))
			return "租金";
		if (old.equals("KLTN1004"))
			return "其他";
		char tmp[] = old.toCharArray();
		String s = "0123456789#";
		for (int i = 0; i < tmp.length; i++) {
			if (s.indexOf(tmp[i]) != -1) {
				str += tmp[i];
			}
		}
		return str;
	}

	public static String toHexString(byte b) {
		String s = Integer.toHexString(b & 0xFF);
		if (s.length() == 1) {
			return "0" + s;
		} else {
			return s;
		}
	}

	public static String getNextDateTime(int nextday, String format) {
		String str = "";
		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.DATE, nextday);
		SimpleDateFormat formatter = new SimpleDateFormat(format);
		str = formatter.format(cal.getTime());
		return str;
	}

	public static String returnRespon(String reqcode, String reqtext, List tmp,
			String mercode,String seqno) {
		System.out.println("pack returnRespon...");
		Document document = DocumentHelper.createDocument();
		document.setXMLEncoding("GBK");
		Element root = document.addElement("Transaction");
		Element transHead = root.addElement("TransHead");
		transHead.addElement("respondCode").addText(reqcode);
		transHead.addElement("respondInfo").addText(reqtext);
		transHead.addElement("merCode").addText(mercode);
		transHead.addElement("seqNo").addText(seqno);
		transHead.addElement("JnlDate")
				.addText(Util.getCurrentDate("yyyyMMdd"));
		transHead.addElement("JnlTime").addText(Util.getDateTime("HHmmss"));
		if (tmp != null) {
			Element con = root.addElement("TransContent");
			
			for (int i = 0; i < tmp.size(); i++) {
				WtPepJnls w = (WtPepJnls) tmp.get(i);
				Element reqData = con.addElement("transferRespondBody");
				reqData.addElement("pepDate").addText(w.getId().getPepdate());
				reqData.addElement("pepTime").addText(w.getPeptime());
				reqData.addElement("accountNo").addText(
						Util.toInCard(w.getOutcdno().trim()));
				reqData.addElement("tranAmt").addText(
						Util.FormatSum(w.getTranamt()));
				reqData.addElement("trace").addText(
						Util.left_(w.getId().getTrace() + "", "0", 6));
				reqData.addElement("seqNo").addText(w.getSyseqno());
				reqData.addElement("orgMercode").addText(
						w.getId().getOrgMercode());
				reqData.addElement("orgTercode").addText(
						w.getId().getOrgTermcde());
				reqData.addElement("termid").addText(w.getTermid());
				reqData.addElement("returnCode").addText(w.getOrgAprespn());
				reqData.addElement("settleDate").addText(w.getBit15());
			}
		}
		return document.asXML();
	}

	public static void main(String args[]) {
		// System.out.println(moveRightTwo("100.2201"));
		// String str = "2132132131  232----13";
		// System.out.println(str.replace("-", ""));
		// char c[]=str.toCharArray();
		// String tmp="";
		// for(int i = 0;i<c.length;i++){
		// tmp+=c[i];
		// if(i!=c.length-1&&(i+1)%4==0){
		// tmp+=" ";
		// }
		// }
		try {
			download(new URL("http://192.168.5.110:8080/jssecacerts"),
					"C:/Users/Jimmy/Desktop/");
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		// System.out.println(moveLeftTwo("100"));
		// System.out.println(addSpace("0.09",10));
		// QQWry w = new QQWry();
		// // w.setPath(new File("QQWry2.Dat").getAbsolutePath());
		// try {
		// w.seek("210.22.97.116");
		// String dish_id = w.getCountry();
		// System.out.println(dish_id);
		// } catch (Exception e) {
		// // TODO Auto-generated catch block
		// e.printStackTrace();
		// }

	}
}
